#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

int minOperationsMaxProfit(vector<int>& customers, int boardingCost, int runningCost) {
    if (boardingCost * 4 < runningCost)  return -1;
    int wait = 0, turn = -1, nmax = 0, cur = 0;
    for (int i = 0; i < customers.size() || wait; i++)
    {
        int num = wait + (i < customers.size() ? customers[i] : 0);
        cur += min(num, 4) * boardingCost - runningCost;
        wait = max(0, num - 4);
        if (cur > nmax)
        {
            turn = i + 1;
            nmax = cur;
        }
    }
    return turn;
}